Passed
Push — master ( 8f169b...36019d )
by Rafael
01:27
created

preview.js ➔ ???   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
nc 4
dl 0
loc 5
rs 9.4285
cc 2
nop 1
1
const $ = jQuery;
2
3
export class Preview {
4
5
	constructor( options ) {
6
		this.options = options || {};
7
		this.options.context = this.options.context ? $( this.options.context ) : $( 'html' );
8
		this.$head = this.options.context.find( 'head' );
9
	}
10
11
	/**
12
	 * Append styles to the head.
13
	 *
14
	 * @since 1.0.0
15
	 */
16
	appendStyles( id, css ) {
17
		let $style = this.$head.find( '#' + id );
18
19
		if ( ! $style.length ) {
20
			$style = $( '<style>' );
21
			$style.attr( 'id', id );
22
			this.$head.append( $style );
23
		}
24
25
		$style.html( css );
26
	}
27
}
28